﻿window.SearchKey = null;
$.MGJ.ProductStorage = [];
(function () {
    var _this = $.MGJ.ProductStorage;
    $.extend($.MGJ.ProductStorage, {
        Execls: function (ele) {
            var Ssearch = $("#Ssearch").val();
            if (!$(ele).find('.no-result').hasClass('no-result')) {
                window.open(ACTION_URL("ExpotExecl", "FleeGoods") + "?Ssearch=" + window.SearchKey);
            }
            else {
                $.L.msgWarning('导出数据不能为空！')
            }
        }
    });
})(jQuery);
(function () {
    var _this = $.MGJ.ProductStorage;
    $.extend($.MGJ.ProductStorage, {
        // 产品入库
        Dialog_StorageInfoObj: null,
        Dialog_StorageInfo: function () {
            this.Dialog_StorageInfoObj = $.L.dialog({
                url: ACTION_URL("StorageInfo", "FleeGoods"),
                title: "输入物流码信息",
                width: 800,
                height: 'auto',

            });
        },

        // 入库编辑
        Dialog_EditStorageObj: null,
        Dialog_EditStorage: function (obj) {
            var TheText;
            var index_1 = $("#WarehousInfo_right tr").index($(obj).parent().parent());
            $("#WarehousInfo tr").each(function () {
                var index_2 = $(this).index();
                if (index_2 == index_1) {
                    TheText = $(this).find(".Status").text();
                }
            })
            var id = $(obj).attr("id");
            if (id == undefined) {
                id = obj;
            }
            if (TheText == "待编辑" || TheText == undefined) {

                this.Dialog_EditStorageObj = $.L.dialog({
                    url: ACTION_URL("EditStorage", "FleeGoods") + "?id=" + id,
                    title: "入库信息",
                    width: 800,
                    height: 'auto',
                    buttons: {
                        "button_save": {
                            type: 'primary',
                            text: '保存',
                            click: function () {
                                var bootstrapValidator = $("#form_EditStorage").data('bootstrapValidator').validate();//触发全部验证
                                if (bootstrapValidator.isValid()) {
                                    _this.Ajax_EditStorage();
                                }
                                else {
                                    $.L.msgError("请检查数据格式！");
                                };
                            }
                        },
                        "button_cancel": {
                            type: 'default',
                            text: '取消',
                            click: function () {
                                _this.Dialog_EditStorageObj.close();
                                _this.Ajax_GetWarehousInfo(1);
                            }
                        }
                    },
                });
            } else {
                this.Dialog_EditStorageObj = $.L.dialog({
                    url: ACTION_URL("EditStorage", "FleeGoods") + "?id=" + id,
                    title: "入库信息",
                    width: 800,
                    height: 'auto',
                    buttons: {
                        "button_cancel": {
                            type: 'default',
                            text: '取消',
                            click: function () {
                                _this.Dialog_EditStorageObj.close();
                                _this.Ajax_GetWarehousInfo(1);
                            }
                        }
                    },
                })
            }
        },
    });
})(jQuery);
(function () {
    var _index = 1;
    var _this = $.MGJ.ProductStorage;
    $.extend($.MGJ.ProductStorage, {
        Ajax_GetWarehousInfo: function (pageIndex) {
            _index = pageIndex;
            window.SearchKey = removeSpace($("#Ssearch").val());
            $.L.ajaxHandle({
                url: ACTION_URL("GetWarehousInfo", "FleeGoods") + "?pageindex=" + pageIndex,
                data: $("#SearchForm").serialize(),
                success: function (response) {
                    $("#WarehousInfo").L_bindingDataList(response);
                    $("#WarehousInfo_right").L_bindingDataList(response);
                    $("#WarehousInfo_left").L_bindingDataList(response);
                    for (var i = 0; i < response.PageData.length; i++) {
                        var TheText = response.PageData[i].Status
                        if (TheText == "0" || TheText == "") {
                            $(".IfTextBtn").eq(i).text("编辑")
                        } else {
                            //    $(".IfTextBtn").eq(i).text("查看")
                            $(".IfTextBtn").eq(i).attr("style", "visibility:hidden;")
                        }
                    }
                }
            });
        },
        //删除
        Ajax_DelWarehousInfo: function (obj) {
            if (confirm("确定要删除吗？")) {
                var id = $(obj).attr("ID");
                $.L.ajaxHandle({
                    url: ACTION_URL("DelWarehousInfo", "FleeGoods"),
                    data: {
                        id: id
                    },
                    success: function (response) {
                        if (response > 0) {
                            _this.Ajax_GetWarehousInfo(_index);
                            $.L.msgSuccess("操作成功");
                        }
                        else {
                            $.L.msgSuccess("操作失败");
                        }
                    }
                });
            }
        },
        //填写物流码
        Ajax_LittleCode: function (BoxCode) {
            var bootstrapValidator = $("#InfoForm").data('bootstrapValidator').validate();//触发全部验证
            if (bootstrapValidator.isValid()) {
                $.L.ajaxHandle({
                    url: ACTION_URL("LittleCode", "FleeGoods"),
                    data: {
                        BoxCode: BoxCode
                    },
                    success: function (response) {
                        var data = eval("(" + response + ")");
                        if (data.id > 0) {
                           
                            _this.Dialog_StorageInfoObj.close();
                            _this.Dialog_EditStorage(data.id);
                        }
                        else {
                            $.L.msgError(data.text);
                        }
                    }
                });
            }
            else {
                $.L.msgError("请检查数据格式！");
            };
        },
        //编辑
        Ajax_EditStorage: function () {
            $.L.ajaxHandle({
                url: ACTION_URL("EditStorageInfo", "FleeGoods"),
                data: $("#form_EditStorage").serialize(),
                success: function (response) {
                    _this.Dialog_EditStorageObj.close();
                    if (response > 0) {
                        _this.Ajax_GetWarehousInfo(1);
                        $.L.msgSuccess("操作成功");
                    }
                    else {
                        $.L.msgSuccess("操作失败");
                    }
                }
            });
        },
        Ajax_ImportHandle: function (e) {
            if (e == "0") {
                return "待编辑";
            } else if (e == "1") {
                return "待导入";
            } else if (e == "2") {
                return "导入成功";
            } else if (e == "3") {
                return "导入失败";
            }
        },
       
    });
})(jQuery);
(function () {
    var _this = $.MGJ.ProductStorage;
    $.extend($.MGJ.ProductStorage, {


    });
})(jQuery);


